package com.pinapel.aixml.ui;
import javax.swing.JTree;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;

import java.io.*;
import com.pinapel.aixml.controller.ITreeController;
//import com.pinapel.aixml.controller.TreeController;
import com.pinapel.aixml.models.EnumModelType;
import com.pinapel.aixml.ui.tree.XMLTreeCellRenderer;
import com.pinapel.aixml.ui.tree.AiXMLTreeModel;

import javax.xml.parsers.*;

import org.w3c.dom.Node;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
//import org.apache.xerces.parsers.*;

public class ArbolUI extends javax.swing.JScrollPane{

    /**
	 * 
	 */
	private static final long serialVersionUID = 201204121742L;
	
	protected JTree jTree;
	private ITreeController cTree;
	private ITreeController mController;
	protected DefaultTreeCellRenderer renderer;
	private javax.swing.tree.DefaultMutableTreeNode treeNode1;
	
	protected TreeModel tModel;
	private TreeModelListener l;

    /**
     * Creates new form InterfazPrincipal
     */
    public ArbolUI() {

    	jTree = new javax.swing.JTree();
    	
        
    	
    	//Lo cargamos para evitar que cargue el JTree por defecto
    	treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("");
        jTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
       
        DefaultTreeCellRenderer renderer_aux=(DefaultTreeCellRenderer)jTree.getCellRenderer();

        renderer_aux.setLeafIcon(null);
        renderer_aux.setClosedIcon(null);
        renderer_aux.setOpenIcon(null);
  
        this.setViewportView(jTree);
    }
   
	public ITreeController getcTree() {
		return cTree;
	}
	public ITreeController getController() {
		return this.mController;
	}
    public void setController(ITreeController cTr){
    	this.mController=cTr;
    }
	public void setcTree(ITreeController cTree) {
		this.cTree = cTree;
	}
	public void draw(TreeModel tree){
		
		tModel=tree;
		renderer = new XMLTreeCellRenderer(tModel.getRoot());
		
		jTree.setModel(tree);
		jTree.setCellRenderer(renderer);
	}
	
}
